package com.example.service.impl;

import com.example.entity.Messages;
import com.example.mapper.MessagesMapper;
import com.example.result.CommonResult;
import com.example.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;

/**
 * @author: tobed
 * @date: 2022/11/18
 * @time: 14:09
 */
@Service
public class MessagesServiceImpl implements MessagesService {

    @Autowired
    MessagesMapper mapper;

    /*查询个人消息*/
    @Override
    public CommonResult listMessage(Integer userId,Integer type) {
        List<Messages> list = mapper.selectMessages(userId,type);
        int i = mapper.countNoRead(userId,type);
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",list);
        map.put("count",i);
        return CommonResult.ok(map);
    }

    /*清理个人消息*/
    @Override
    public CommonResult cleanNoRead(Integer userId, Integer type) {
        int i = mapper.cleanNoRead(userId,type);
        if (i!=0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail(888,"网络异常");
        }
    }

    /*修改状态*/
    @Override
    public CommonResult changeStatus(Integer id) {
        int i = mapper.updatStatus(id);
        if (i!=0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail(888,"网络异常");
        }
    }
}
